*******************************************************************************
* Load and append data sets
*******************************************************************************

use dataset_gallup, clear
append using dataset_anes
append using dataset_gss

*******************************************************************************
* Keep only if non-missing on race subsets
*******************************************************************************

keep if (data == "anes" & !mi(ftBlack)) | ///
	(data == "gallup" & !mi(confidenceBlack)) | ///
	(data == "gss" & !mi(spend_lawenfBlack))

*******************************************************************************
* Figure
*******************************************************************************

foreach y in confidence ft spend_lawenf {
	
	local mytext1 text(0.71 1997 "White")
	local mytext2 text(0.47 1997 "Black")

	if "`y'" != "confidence" local mytext1
	if "`y'" != "confidence" local mytext2	
	
	if "`y'" == "confidence" local mytitle "(a) Confidence (Gallup)"
	if "`y'" == "ft" local mytitle "(b) Feeling thermometer (ANES)"
	if "`y'" == "spend_lawenf" local mytitle "(c) Spending (GSS)"

	#delimit;

	gr tw
		(sc `y'White year, col(black) msym(Oh) msize(medsmall))
		(sc `y'Black year, col(black) msym(O) msize(medsmall))
		(lfit `y'White year, col(black))
		(lfit `y'Black year, col(black) lpat(dash))
		, 	
			ylab(, angle(horiz))
			legend(off)
			plotregion(style(none))
			ytitle("")
			xtitle("")
			xlab(1995(5)2020)
			`mytext1'
			`mytext2'
			name(g`y'L, replace)
			title("By race")
			;
			
	#delimit cr

	gr close

	#delimit;

	gr tw
		(sc `y'WhiteBlack year, col(black) msize(medsmall))
		(lfit `y'WhiteBlack year, col(black))
		, 	
			ylab(, angle(horiz))
			legend(off)
			plotregion(style(none))
			ytitle("")
			xtitle("")
			xlab(1995(5)2020)
			name(g`y'R, replace)
			title("White-Black gap")
			;
			
	#delimit cr

	gr close

	gr combine g`y'L g`y'R, name(g`y', replace) title("`mytitle'")

	gr close

}

gr combine gconfidence gft gspend_lawenf, cols(1) imargin(zero) ///
	ysize(3) xsize(3)

*******************************************************************************
* Export
*******************************************************************************

gr export "_output/figure2.eps", replace

*******************************************************************************
* End
*******************************************************************************
